#!/bin/bash 
#jdk环境变量
export JAVA_HOME=/usr/local/mywork/jdk1.8.0_131
export JAVA_BIN=$JAVA_HOME/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
CODE_PATH=/usr/local/myworkspace/javawork/springboot/
APP_NAME=springboot-2.0.0.jar 
is_exist(){
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
#如果不存在返回1,存在返回0 
if [ -z "${pid}" ]; then
return 1
else
return 0
fi
}
echo "判断程序是否在运行"
is_exist
if [ $? -eq "0" ]; then
kill -9 $pid
echo "${APP_NAME} 停止运行"
else
echo "${APP_NAME} 没有运行" 
fi
#拉取代码
cd ${CODE_PATH}
echo "拉取代码"
git pull
#编译代码
echo "编译代码"
mvn clean package -Dmaven.test.skip=true
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} 正在运行，请手动关闭" 
else
nohup java -jar target/${APP_NAME} --spring.profiles.active=pro > springboot.log 2>&1 &
echo "程序正在启动..."
fi
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} 运行成功 "
else
echo "${APP_NAME} 运行失败 "
fi
exit
